package com.naizhuai.Model.db.ainote;

import android.arch.persistence.room.ColumnInfo;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;
import android.text.TextUtils;

import com.naizhuai.Model.db.Tables;

import java.util.Date;

/**
 * @author：lichenxi
 * @date 2018/2/22 11
 * email：525603977@qq.com
 * Fighting
 */
@Entity(tableName = Tables.NOTE_TABLE)
public class Note {
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "noteid")
    public int noteid;

    @ColumnInfo(name = "title")
    public  final String title;

    @ColumnInfo(name = "content")
    public final String content;

    @ColumnInfo(name = "creation")
    public Date creation;

    @ColumnInfo(name = "last_update")
    public Date last_update;

    public Note(String title, String content) {
       this(title,content,new Date(),new Date());
    }
    private Note(String title, String content,Date createion,Date last_update) {
        this.title = title;
        this.content = content;
        this.creation=createion;
        this.last_update=last_update;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Note note = (Note) o;

        return noteid == note.noteid;
    }

    @Override
    public int hashCode() {
        return noteid;
    }

    public int getNoteid() {
        return noteid;
    }

    public void setNoteid(int noteid) {
        this.noteid = noteid;
    }

    public Date getCreation() {
        return creation;
    }

    public void setCreation(Date creation) {
        this.creation = creation;
    }

    public Date getLast_update() {
        return last_update;
    }

    public void setLast_update(Date last_update) {
        this.last_update = last_update;
    }

    public boolean isEmpty() {
        return TextUtils.isEmpty(title) &&
                TextUtils.isEmpty(content);
    }

    public enum NoteFilterType {

        TITLE,

        /**
         * Filters only the active (not completed yet) tasks.
         */
        CREATION,

        /**
         * Filters only the completed tasks.
         */
        LAST_UPDATE
    }

    public boolean isSelected() {
        return selected;
    }

    @Ignore
    private boolean selected = false;

    public boolean setSelected(boolean selected) {
        if (this.selected == selected)
            return false;
        this.selected = selected;
        return true;
    }

    public boolean toggleSelected() {
        selected = !selected;
        return selected;
    }
}
